package com.example.lc.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import java.util.List;
import com.example.lc.R;
import com.example.lc.bean.Student;

public class StudentAdapter extends RecyclerView.Adapter<StudentAdapter.ViewHolder> {
    private List<Student> studentList;
    private LayoutInflater inflater;

    public StudentAdapter(List<Student> studentList, Context context) {
        this.studentList = studentList;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_student, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Student student = studentList.get(position);
        holder.studentId.setText("学生id：" + String.valueOf(student.getId()));
        holder.studentName.setText("姓名：" + student.getName());
        holder.studentNumber.setText("学号：" +student.getStudentNumber());
        holder.studentUsername.setText("用户名：" +student.getUsername());
        holder.studentClass.setText("班级：" +student.getClassName());
    }

    @Override
    public int getItemCount() {
        return studentList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView studentId;
        TextView studentName;
        TextView studentNumber;
        TextView studentUsername;
        TextView studentClass;

        ViewHolder(View view) {
            super(view);
            studentId = view.findViewById(R.id.student_id);
            studentName = view.findViewById(R.id.student_name);
            studentNumber = view.findViewById(R.id.student_number);
            studentUsername = view.findViewById(R.id.student_username);
            studentClass = view.findViewById(R.id.student_class);
        }
    }
}
